using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SCS.Common.Models;
namespace SCS.DAL.Mapping
{
    public class TeacherMap : EntityTypeConfiguration<Teacher>
    {
        public TeacherMap()
        {
            // Primary Key
            this.HasKey(t => t.teacherID);

            // Properties
            this.Property(t => t.teacherID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.teacherName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.gender)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(1);

            this.Property(t => t.mobile)
                .HasMaxLength(15);

            this.Property(t => t.address)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Teacher");
            this.Property(t => t.teacherID).HasColumnName("teacherID");
            this.Property(t => t.teacherName).HasColumnName("teacherName");
            this.Property(t => t.gender).HasColumnName("gender");
            this.Property(t => t.mobile).HasColumnName("mobile");
            this.Property(t => t.address).HasColumnName("address");
            this.Property(t => t.userID).HasColumnName("userID");
            this.Property(t => t.deactived).HasColumnName("deactived");
            this.Property(t => t.dateOfBirth).HasColumnName("dateOfBirth");
            this.Property(t => t.subjectID).HasColumnName("subjectID");

            // Relationships
            this.HasOptional(t => t.MembershipUser)
                .WithMany(t => t.Teachers)
                .HasForeignKey(d => d.userID);
            this.HasOptional(t => t.Subject)
                .WithMany(t => t.Teachers)
                .HasForeignKey(d => d.subjectID);

        }
    }
}

